<template>
  <el-card style="max-width: 99%">
    <template #header>
      <div class="card-header">
        <span>景点推荐</span>
      </div>
    </template>
    <el-row style="margin-bottom: 20px">
      <el-col :span="5">
        <el-form :model="form" style="max-width: 200px;margin-left: 25px">
          <el-form-item label="景点名称">
            <el-input v-model="name" placeholder="请输入景点名称" />
          </el-form-item>
        </el-form>
      </el-col>
      <el-col :span="19">
        <el-button type="primary" @click="cx()">搜索</el-button>
        <el-button @click="cz()">重置</el-button>
      </el-col>
    </el-row>
    <el-table :data="list" border style="margin-bottom: 15px">
      <el-table-column prop="name" label="景点" width="180" />
      <el-table-column prop="topicName" label="主题" width="180" />
      <el-table-column prop="introduce" label="简介" />
      <el-table-column prop="price" label="价格" />
      <el-table-column prop="appraise" label="星级">
        <template #default="scope">
          <el-rate v-if="scope.row.appraise==4" v-model="value[0]" disabled text-color="#ff9900"/>
          <el-rate v-if="scope.row.appraise==3" v-model="value[1]" disabled text-color="#ff9900"/>
          <el-rate v-if="scope.row.appraise==2" v-model="value[2]" disabled text-color="#ff9900"/>
          <el-rate v-if="scope.row.appraise==1" v-model="value[3]" disabled text-color="#ff9900"/>
        </template>
      </el-table-column>
      <el-table-column prop="recommend" label="是否推荐">
        <template #default="scope">
          {{scope.row.recommend==1?'推荐':'不推荐'}}
        </template>
      </el-table-column>
      <el-table-column prop="views" label="浏览量"/>
      <el-table-column label="操作" >
        <template #default="scope">
          <el-button :icon="Select" circle @click="updateAttractions(scope.row)"/>
          <el-button :icon="CloseBold" circle  @click="updateAttractions2(scope.row)"/>
        </template>
      </el-table-column>
    </el-table>
    <div style="margin: 0 auto;width: 300px">
      <el-pagination @current-change="handleCurrentChange"
          size="small" background layout="prev, pager, next" :total="count" :page-size=pageSize class="mt-4"/>
    </div>
  </el-card>
</template>

<script>
import {selectAllAttractions, updateAttractions, updateAttractions2} from "@/api/vue3.js"
import {ElMessage} from "element-plus";
import {CloseBold, Select} from "@element-plus/icons-vue";
export default {
  name: 'Landscape',
  computed: {
    CloseBold() {
      return CloseBold
    },
    Select() {
      return Select
    }
  },
  data(){
    return {
      name:'',//景点名称
      list:[],//景点列表
      count:0,//总条数
      pageSize:5,//每页条数
      pageNum:1,//当前页码
      value:[2,3,4,5],
    }
  },
  mounted() {
    this.selectList()
  },
  methods: {
    cx(){
      this.name
      this.selectList()
    },
    cz(){
      this.name=''
      this.selectList()
    },
    selectList(){
      selectAllAttractions(this.name,this.pageNum,this.pageSize).then(res=>{
        this.list=res.data.data.list
        this.count=res.data.data.count
      })
    },
    handleCurrentChange(val) {//当前页码改变的事件
      this.pageNum = val;
      this.selectList()
    },
    updateAttractions2(data){
      updateAttractions2(data).then(res=>{
        if (res.data.code==222){
          ElMessage.success("修改成功")
          this.selectList()
        }else{
          ElMessage.error(res.data.msg)
        }
      })
    },
    updateAttractions(data){
      updateAttractions(data).then(res=>{
        if (res.data.code==222){
          ElMessage.success("修改成功")
          this.selectList()
        }else{
          ElMessage.error(res.data.msg)
        }
      })
    }
  }
}
</script>

<style scoped>
.el-card{
  width: 100%;
  height: 600px;
  background-color: white;
  margin-top: 20px;
  border-radius: 30px;
}
.el-table{
  margin: 0 auto;
  width: 96%;
}
</style>